package com.zhida.smartcontrol.pagectrl.projectdetail.search.searchdetails;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.jay.tools.base.BaseDialogFragment;
import com.jay.tools.ui.ButtonStyle;
import com.jay.tools.ui.Cbox;
import com.jay.tools.ui.TopBarView;
import com.jay.tools.ui.swipemenu.SwipeMenuLayout;
import com.jay.tools.utils.EventBusUtils;
import com.jay.tools.utils.ResUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.Const;
import com.zhida.smartcontrol.common.bean.LampBean;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.dialog.deldevicedialog.DelDeviceDIalogFragment;
import com.zhida.smartcontrol.dialog.delqddialog.DelQdDialogFragment;
import com.zhida.smartcontrol.dialog.dimmerdialog.DimmerDialogFragment;
import com.zhida.smartcontrol.dialog.jieridialog.JieRiDialogFragment;
import com.zhida.smartcontrol.dialog.kgsjdialog.KgsjDialogFragment;
import com.zhida.smartcontrol.dialog.kzlxdialog.KzlxDialogFragment;
import com.zhida.smartcontrol.dialog.lampkzlxdialog.LampKzlxDialogFragment;
import com.zhida.smartcontrol.dialog.lampsjjzdialog.LampSjjzDialogFragment;
import com.zhida.smartcontrol.dialog.nbdialog.NBDialogFragment;
import com.zhida.smartcontrol.dialog.sjjzdialog.SjjzDialogFragment;
import com.zhida.smartcontrol.dialog.switchlightdialog.SwitchLightDialogFragment;
import com.zhida.smartcontrol.dialog.tdkgdialog.TdkgDialogFragment;
import com.zhida.smartcontrol.mvp.MVPBaseFragment;
import com.zhida.smartcontrol.pagectrl.lampmanager.EditLampOkEvent;
import com.zhida.smartcontrol.pagectrl.lampmanager.LampManagerFragment;
import com.zhida.smartcontrol.pagectrl.lampmanager.editlamp.EditLampFragment;
import com.zhida.smartcontrol.pagectrl.lampmanager.lampdetail.LampDetailFragment;
import com.zhida.smartcontrol.pagectrl.projectdetail.zonemanager.adddevice.AddDeviceFragment;
import com.zhida.smartcontrol.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;


public class SearchDetailsFragment extends MVPBaseFragment<SearchDetailsContract.View, SearchDetailsPresenter> implements SearchDetailsContract.View {
    @BindView(R.id.top)
    TopBarView top;
    @BindView(R.id.cbox)
    TextView cbox;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.ll_1)
    RelativeLayout ll1;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_online)
    TextView tvOnline;
    @BindView(R.id.tv_mode)
    TextView tvMode;
    @BindView(R.id.ll_2)
    LinearLayout ll2;
    @BindView(R.id.tv_jiao_shi)
    TextView tvJiaoShi;
    @BindView(R.id.ll_3)
    LinearLayout ll3;
    @BindView(R.id.tv_data)
    TextView tvData;
    @BindView(R.id.iv_0)
    ImageView iv0;
    @BindView(R.id.iv_1)
    ImageView iv1;
    @BindView(R.id.iv_2)
    ImageView iv2;
    @BindView(R.id.iv_3)
    ImageView iv3;
    @BindView(R.id.iv_4)
    ImageView iv4;
    @BindView(R.id.iv_5)
    ImageView iv5;
    @BindView(R.id.iv_6)
    ImageView iv6;
    @BindView(R.id.iv_7)
    ImageView iv7;
    @BindView(R.id.ll_4)
    LinearLayout ll4;
    @BindView(R.id.tv_lamp_num)
    TextView tvLampNum;
    @BindView(R.id.ll_dd)
    LinearLayout llDd;
    @BindView(R.id.rl_item)
    RelativeLayout rlItem;
    @BindView(R.id.btn_edit)
    ButtonStyle btnEdit;
    @BindView(R.id.btn_del)
    ButtonStyle btnDel;
    @BindView(R.id.swipe_layout)
    SwipeMenuLayout swipeLayout;
    @BindView(R.id.cbox_dandeng)
    TextView cboxDandeng;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_single_detail)
    TextView tvSingleDetail;
    @BindView(R.id.ll_dandeng_1)
    LinearLayout llDandeng1;
    @BindView(R.id.tv_address_dandeng)
    TextView tvAddressDandeng;
    @BindView(R.id.tv_control)
    TextView tvControl;
    @BindView(R.id.ll_dandeng_2)
    LinearLayout llDandeng2;
    @BindView(R.id.tv_jiao_shi_dandeng)
    TextView tvJiaoShiDandeng;
    @BindView(R.id.ll_dandeng_3)
    LinearLayout llDandeng3;
    @BindView(R.id.tv_time_dandeng)
    TextView tvTimeDandeng;
    @BindView(R.id.tv_brightness)
    TextView tvBrightness;
    @BindView(R.id.ll_bright)
    LinearLayout llBright;
    @BindView(R.id.ll_item)
    LinearLayout llItem;
    @BindView(R.id.btn_edit_dandeng)
    ButtonStyle btnEditDandeng;
    @BindView(R.id.btn_del_dandeng)
    ButtonStyle btnDelDandeng;
    @BindView(R.id.swipe_layout_dandeng)
    SwipeMenuLayout swipeLayoutDandeng;
    @BindView(R.id.cbox_shuangdeng)
    TextView cboxShuangdeng;
    @BindView(R.id.tv_detail)
    TextView tvDetail;
    @BindView(R.id.tv_control_shuangdeng)
    TextView tvControlShuangdeng;
    @BindView(R.id.ll_shuangdeng_1)
    LinearLayout llShuangdeng1;
    @BindView(R.id.tv_address_shuangdeng)
    TextView tvAddressShuangdeng;
    @BindView(R.id.cbox_main)
    Cbox cboxMain;
    @BindView(R.id.iv_main)
    ImageView ivMain;
    @BindView(R.id.tv_brightness_main)
    TextView tvBrightnessMain;
    @BindView(R.id.ll_main)
    LinearLayout llMain;
    @BindView(R.id.cbox_aux)
    Cbox cboxAux;
    @BindView(R.id.iv_aux)
    ImageView ivAux;
    @BindView(R.id.tv_brightness_aux)
    TextView tvBrightnessAux;
    @BindView(R.id.ll_aux)
    LinearLayout llAux;
    @BindView(R.id.tv_jiao_shi_shuangdeng)
    TextView tvJiaoShiShuangdeng;
    @BindView(R.id.ll_shuangdeng_3)
    LinearLayout llShuangdeng3;
    @BindView(R.id.tv_time_shuangdeng)
    TextView tvTimeShuangdeng;
    @BindView(R.id.ll_item_shuangdeng)
    LinearLayout llItemShuangdeng;
    @BindView(R.id.btn_edit_shuangdeng)
    ButtonStyle btnEditShuangdeng;
    @BindView(R.id.btn_del_shuangdeng)
    ButtonStyle btnDelShuangdeng;
    @BindView(R.id.swipe_layout_shuangdeng)
    SwipeMenuLayout swipeLayoutShuangdeng;
    @BindView(R.id.tv_kzlx)
    TextView tvKzlx;
    @BindView(R.id.fl_kzlx)
    FrameLayout flKzlx;
    @BindView(R.id.tv_jrms)
    TextView tvJrms;
    @BindView(R.id.fl_jrms)
    FrameLayout flJrms;
    @BindView(R.id.tv_sjjz)
    TextView tvSjjz;
    @BindView(R.id.fl_sjjz)
    FrameLayout flSjjz;
    @BindView(R.id.tv_tdkg)
    TextView tvTdkg;
    @BindView(R.id.fl_tdkg)
    FrameLayout flTdkg;
    @BindView(R.id.tv_kgsj)
    TextView tvKgsj;
    @BindView(R.id.fl_kgsj)
    FrameLayout flKgsj;
    @BindView(R.id.tv_yxxm)
    TextView tvYxxm;
    @BindView(R.id.fl_yxxm)
    FrameLayout flYxxm;
    @BindView(R.id.tv_tcjx)
    TextView tvTcjx;
    @BindView(R.id.fl_tcjx)
    FrameLayout flTcjx;
    @BindView(R.id.tv_fuwei)
    TextView tvFuwei;
    @BindView(R.id.fl_fuwei)
    FrameLayout flFuwei;
    @BindView(R.id.rl_bottom_group)
    RelativeLayout rlBottomGroup;
    @BindViews({R.id.fl_kzlx, R.id.fl_jrms, R.id.fl_sjjz, R.id.fl_tdkg, R.id.fl_kgsj, R.id.fl_yxxm, R.id.fl_tcjx, R.id.fl_fuwei})
    List<FrameLayout> mFlBtns;
    @BindViews({R.id.tv_kzlx, R.id.tv_jrms, R.id.tv_sjjz, R.id.tv_tdkg, R.id.tv_kgsj, R.id.tv_yxxm, R.id.tv_tcjx, R.id.tv_fuwei})
    List<TextView> mTvBtns;
    private int mColorGreen, mColorRed;
    private int mBlue, mGray, mWhite;

    private Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    mHandler.postDelayed(refreshDevice, 5000);
                    break;
                case 1:
                    mHandler.removeCallbacks(refreshDevice);
                    break;
                case 2:
                    mHandler.post(refreshDevice);
                    break;
            }
        }
    };

    private Runnable refreshDevice = new Runnable() {
        @Override
        public void run() {
            mPresenter.requestLampData(getArguments().getString("id"));
        }
    };

    public static SearchDetailsFragment newInstance(String projectId, String projectName, String switchType) {
        Bundle args = new Bundle();
        args.putString("id", projectId);
        args.putString("pName", projectName);
        args.putString("switchType", switchType);
        SearchDetailsFragment fragment = new SearchDetailsFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.layout_search_details;
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {
        top.setTitle(getArguments().getString("pName"));
        top.setOnTopBarClickListener(new TopBarView.OnTopBarClick() {
            @Override
            public void leftClick() {
                pop();
            }

            @Override
            public void rightClick() {
            }
        });
        mColorGreen = ResUtil.getColor(getContext(), R.color.c_22D49C);
        mColorRed = ResUtil.getColor(getContext(), R.color.c_FF4D62);
        mWhite = ResUtil.getColor(getProxyActivity(), R.color.c_FFFFFF);
        mBlue = ResUtil.getColor(getContext(), R.color.c_3862FF);
        mGray = ResUtil.getColor(getContext(), R.color.c_999999);
        mPresenter.requestLampData(getArguments().getString("id"));
    }

    private LampBean info;
    private LampSwitchBean info1;

    @Override
    public void showData(LampBean info) {
        this.info = info;
        lampBeans.add(info);
        swipeLayout.setVisibility(View.VISIBLE);
        cbox.setText(info.getImei());
        tvTime.setText("更新：" + info.getUpdateDate());
        tvAddress.setText(info.getAddress());
        tvMode.setText(info.getControlType().equals(Const.AUTO) ? "自" : "手");

        tvJiaoShi.setText("校时：" + info.getClockUpdateTime());
        if (info.getUpdateTimeFlag().equals("0")) {
            tvJiaoShi.setTextColor(mColorGreen);
        } else {
            tvJiaoShi.setTextColor(mColorRed);
        }

        tvTime.setText("更新：" + info.getUpdateDate());
        if (info.getUpdateStatus().equals("0")) {
            tvTime.setTextColor(mColorGreen);
        } else {
            tvTime.setTextColor(mColorRed);
        }

        List<ImageView> ivList = new ArrayList<>();
        ivList.add(iv0);
        ivList.add(iv1);
        ivList.add(iv2);
        ivList.add(iv3);
        ivList.add(iv4);
        ivList.add(iv5);
        ivList.add(iv6);
        ivList.add(iv7);
        setChannel(ivList, info.getSwitchType(), info.getReturnValueTxt());

        tvLampNum.setText(info.getChildrenCount() + "");
        flFuwei.setVisibility(View.VISIBLE);
        flJrms.setVisibility(View.VISIBLE);
        flKgsj.setVisibility(View.VISIBLE);
        flKzlx.setVisibility(View.VISIBLE);
        flSjjz.setVisibility(View.VISIBLE);
        flTcjx.setVisibility(View.VISIBLE);
        flTdkg.setVisibility(View.VISIBLE);
        flYxxm.setVisibility(View.VISIBLE);

    }

    @Override
    public void showData(LampSwitchBean info) {
        info1 = info;
        lampSwitchBeans.add(info);
        switch (Integer.parseInt(info.getSwitchType())) {
            case Const.NB_SINGLE:
            case Const.PLC_SINGLE:
            case Const.ZIG_BEE_SINGLE:
                swipeLayoutDandeng.setVisibility(View.VISIBLE);
                cboxDandeng.setText(info.getImei());
                tvJiaoShiDandeng.setText("校时：" + info.getClockUpdateTime());
                if (info.getUpdateTimeFlag().equals("0")) {
                    // 显示绿色
                    tvJiaoShiDandeng.setTextColor(mColorGreen);
                } else {
                    tvJiaoShiDandeng.setTextColor(mColorRed);
                }

                tvTimeDandeng.setText("更新：" + info.getUpdateDate());
                if (info.getUpdateStatus().equals("0")) {
                    // 绿色
                    tvTimeDandeng.setTextColor(mColorGreen);
                } else {
                    tvTimeDandeng.setTextColor(mColorRed);
                }

                String type;
                int sType = Integer.parseInt(info.getSwitchType());
                switch (sType) {
                    case Const.NB_SINGLE:
                        type = "N";
                        break;
                    case Const.PLC_SINGLE:
                        type = "P";
                        break;
                    default:
                        type = "Z";
                        break;
                }
                tvType.setText(type);
                tvAddressDandeng.setText(info.getAddress());
                tvControl.setText(info.getControlType().equals(Const.AUTO) ? "自" : "手");

                String brightNess = info.getBrightNess();
                if (TextUtils.isEmpty(brightNess)) {
                    llBright.setVisibility(View.GONE);
                } else {
                    llBright.setVisibility(View.VISIBLE);
                    tvBrightness.setText(MyUtils.getBrightNess(brightNess));
                }
                flKzlx.setVisibility(View.VISIBLE);
                flSjjz.setVisibility(View.VISIBLE);
                flKgsj.setVisibility(View.VISIBLE);
                flTdkg.setVisibility(View.VISIBLE);
                flJrms.setVisibility(View.VISIBLE);
                tvJrms.setText("调光");
                tvTdkg.setText("开/关灯");
                break;
            case Const.NB_DOUBLE:
                swipeLayoutShuangdeng.setVisibility(View.VISIBLE);
                cboxShuangdeng.setText(info.getImei());
                tvControlShuangdeng.setText(info.getControlType().equals(Const.AUTO) ? "自" : "手");
                tvAddressShuangdeng.setText(info.getAddress());

                tvJiaoShiShuangdeng.setText("校时：" + info.getClockUpdateTime());
                if (info.getUpdateTimeFlag().equals("0")) {
                    // 显示绿色
                    tvJiaoShiShuangdeng.setTextColor(mColorGreen);
                } else {
                    tvJiaoShiShuangdeng.setTextColor(mColorRed);
                }

                tvTimeShuangdeng.setText("更新：" + info.getUpdateDate());
                if (info.getUpdateStatus().equals("0")) {
                    // 绿色
                    tvTimeShuangdeng.setTextColor(mColorGreen);
                } else {
                    tvTimeShuangdeng.setTextColor(mColorRed);
                }

                String brightNess1 = info.getBrightNess();
                if (TextUtils.isEmpty(brightNess1)) {
                    ivMain.setVisibility(View.GONE);
                    ivAux.setVisibility(View.GONE);
                    tvBrightnessMain.setVisibility(View.GONE);
                    tvBrightnessAux.setVisibility(View.GONE);
                } else {
                    ivMain.setVisibility(View.VISIBLE);
                    ivAux.setVisibility(View.VISIBLE);
                    tvBrightnessMain.setVisibility(View.VISIBLE);
                    tvBrightnessAux.setVisibility(View.VISIBLE);
                    tvBrightnessMain.setText(MyUtils.getBrightNess(brightNess1.substring(0, 1)));
                    tvBrightnessAux.setText(MyUtils.getBrightNess(brightNess1.substring(1)));
                }
                flKzlx.setVisibility(View.VISIBLE);
                flSjjz.setVisibility(View.VISIBLE);
                flKgsj.setVisibility(View.VISIBLE);
                flTdkg.setVisibility(View.VISIBLE);
                flJrms.setVisibility(View.VISIBLE);
                tvJrms.setText("调光");
                tvTdkg.setText("开/关灯");
                break;
        }
    }

    // 设置通道状态  // 0关闭， 1开启
    private void setChannel(List<ImageView> ivList, String switchType, String returnValueTxt) {
        int num = getChannelNum(switchType);
        String valueTxt = new StringBuffer(returnValueTxt).reverse().toString();
        String[] split = valueTxt.split("");
        int size = ivList.size();
        for (int i = 0; i < size; i++) {
            ImageView iv = ivList.get(i);
            if (i < num) {
                iv.setVisibility(View.VISIBLE);
                if (TextUtils.isEmpty(split[0])) {
                    iv.setImageResource(getRes(split[i + 1]));
                } else {
                    iv.setImageResource(getRes(split[i]));
                }
            } else {
                iv.setVisibility(View.GONE);
            }
        }
    }

    // 获取通道数量
    private int getChannelNum(String switchType) {
        int type = Integer.parseInt(switchType);
        int index;
        switch (type) {
            case Const.NB_SINGLE:
            case Const.ZIG_BEE_SINGLE:
                index = 1;
                break;
            case Const.NB_DOUBLE:
                index = 2;
                break;
            case Const.SWITCH:
                index = 8;
                break;
            default:
                index = 4;
                break;
        }
        return index;
    }

    private int getRes(String state) {
        if (state.equals("1")) { //1,开启
            return R.drawable.ic_td_open;
        } else {// if (state.equals("0")) { //0,关闭
            return R.drawable.ic_td_close;
        }
    }

    private ArrayList<LampBean> lampBeans = new ArrayList<>();
    private ArrayList<LampSwitchBean> lampSwitchBeans = new ArrayList<>();

    @OnClick({R.id.ll_dd, R.id.fl_kzlx, R.id.fl_jrms, R.id.fl_sjjz, R.id.fl_tdkg, R.id.fl_kgsj, R.id.fl_yxxm, R.id.fl_tcjx, R.id.fl_fuwei,R.id.btn_edit, R.id.btn_del, R.id.btn_edit_dandeng, R.id.btn_del_dandeng, R.id.btn_edit_shuangdeng, R.id.btn_del_shuangdeng})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_dd:
                start(LampManagerFragment.newInstance(info));
                break;
            case R.id.fl_kzlx:
                clickBottomBtn(0);
                switch (Integer.parseInt(getArguments().getString("switchType"))) {
                    case Const.NB_SINGLE:
                    case Const.PLC_SINGLE:
                    case Const.ZIG_BEE_SINGLE:
                        showDialog(LampKzlxDialogFragment.newInstance(Integer.parseInt(getArguments().getString("switchType")), lampSwitchBeans));
                        break;
                    case Const.NB_DOUBLE:
                        showDialog(LampKzlxDialogFragment.newInstance(Const.NB_DOUBLE, lampSwitchBeans));
                        break;
                    default:
                        showDialog(KzlxDialogFragment.newInstance(info.getSwitchType(), lampBeans));
                        break;
                }
                break;
            case R.id.fl_jrms:
                clickBottomBtn(1);
                switch (Integer.parseInt(getArguments().getString("switchType"))) {
                    case Const.NB_SINGLE:
                    case Const.PLC_SINGLE:
                    case Const.ZIG_BEE_SINGLE:
                        showDialog(DimmerDialogFragment.newInstance(Integer.parseInt(getArguments().getString("switchType")), lampSwitchBeans));
                        break;
                    case Const.NB_DOUBLE:
                        showDialog(DimmerDialogFragment.newInstance(Const.NB_DOUBLE, lampSwitchBeans));
                        break;
                    default:
                        showDialog(JieRiDialogFragment.newInstance(info.getSwitchType(), lampBeans));
                        break;
                }
                break;
            case R.id.fl_sjjz:
                clickBottomBtn(2);
                switch (Integer.parseInt(getArguments().getString("switchType"))) {
                    case Const.NB_SINGLE:
                    case Const.PLC_SINGLE:
                    case Const.ZIG_BEE_SINGLE:
                        showDialog(LampSjjzDialogFragment.newInstance(Integer.parseInt(getArguments().getString("switchType")), lampSwitchBeans));
                        break;
                    case Const.NB_DOUBLE:
                        showDialog(LampSjjzDialogFragment.newInstance(Const.NB_DOUBLE, lampSwitchBeans));
                        break;
                    default:
                        showDialog(SjjzDialogFragment.newInstance(info.getSwitchType(), lampBeans));
                        break;
                }
                break;
            case R.id.fl_tdkg:
                clickBottomBtn(3);
                switch (Integer.parseInt(getArguments().getString("switchType"))) {
                    case Const.NB_SINGLE:
                    case Const.PLC_SINGLE:
                    case Const.ZIG_BEE_SINGLE:
                        showDialog(SwitchLightDialogFragment.newInstance(Integer.parseInt(getArguments().getString("switchType")), lampSwitchBeans));
                        break;
                    case Const.NB_DOUBLE:
                        showDialog(SwitchLightDialogFragment.newInstance(Const.NB_DOUBLE, lampSwitchBeans));
                        break;
                    default:
                        showDialog(TdkgDialogFragment.newInstance(info.getSwitchType(), lampBeans));
                        break;
                }
                break;
            case R.id.fl_kgsj:
                clickBottomBtn(4);
                switch (Integer.parseInt(getArguments().getString("switchType"))) {
                    case Const.NB_SINGLE:
                    case Const.PLC_SINGLE:
                    case Const.ZIG_BEE_SINGLE:
                        showDialog(NBDialogFragment.newInstance(Integer.parseInt(getArguments().getString("switchType")), lampSwitchBeans));
                        break;
                    case Const.NB_DOUBLE:
                        showDialog(NBDialogFragment.newInstance(Const.NB_DOUBLE, lampSwitchBeans));
                        break;
                    default:
                        showDialog(KgsjDialogFragment.newInstance(info.getSwitchType(), lampBeans));
                        break;
                }
                break;
            case R.id.fl_yxxm:
                clickBottomBtn(5);
                NormalDialog dialog = new NormalDialog(getContext());
                dialog.content("请选择运行/休眠模式?")
                        .style(NormalDialog.STYLE_TWO)//
                        .title("温馨提示")
                        .btnNum(3)
                        .btnTextColor(
                                R.color.c_666666, R.color.c_3862FF, R.color.c_FF4D62
                        )
                        .btnText("取消", "运行", "休眠")
                        .titleTextSize(23f)
                        .show();
                dialog.setOnBtnClickL((OnBtnClickL) () -> {
                            dialog.dismiss();
                            resetBtns();
                        }, (OnBtnClickL) () -> {
                            dialog.dismiss();
                            mPresenter.runningModel(lampBeans, 2);
                            resetBtns();
                        },
                        (OnBtnClickL) () -> {
                            dialog.dismiss();
                            mPresenter.runningModel(lampBeans, 3);
                            resetBtns();
                        }
                );
                break;
            case R.id.fl_tcjx:
                clickBottomBtn(6);
                NormalDialog dialog1 = new NormalDialog(getContext());
                dialog1.content("是否退出检修模式?")
                        .style(NormalDialog.STYLE_TWO)//
                        .title("温馨提示")
                        .btnNum(2)
                        .btnTextColor(
                                R.color.c_666666, R.color.c_666666
                        )
                        .btnText("是", "否")
                        .titleTextSize(23f)
                        .show();
                dialog1.setOnBtnClickL((OnBtnClickL) () -> {
                            dialog1.dismiss();
                            mPresenter.switchRepair(lampBeans, 1);
                            resetBtns();
                        },
                        (OnBtnClickL) () -> {
                            dialog1.dismiss();
                            resetBtns();
                        }
                );
                break;
            case R.id.fl_fuwei:
                clickBottomBtn(7);
                NormalDialog dialog2 = new NormalDialog(getContext());
                dialog2.content("是否复位?")
                        .style(NormalDialog.STYLE_TWO)//
                        .title("温馨提示")
                        .btnNum(2)
                        .btnTextColor(
                                R.color.c_666666, R.color.c_666666
                        )
                        .btnText("是", "否")
                        .titleTextSize(23f)
                        .show();
                dialog2.setOnBtnClickL((OnBtnClickL) () -> {
                            dialog2.dismiss();
                            mPresenter.resetSwitch(lampBeans);
                            resetBtns();
                        },
                        (OnBtnClickL) () -> {
                            dialog2.dismiss();
                            resetBtns();
                        }
                );
                break;
            case R.id.btn_edit:
//                info.setGroupId(mGroupId);
//                info.setProjectName(mProjectName);
//                info.setGroupName(mGroupName);
//                info.setSwitchType(mSwitchType);
//                info.setSwitchTypeTxt(mSwitchName);
                start(AddDeviceFragment.newInstance(Const.TYPE_EDIT, info));
                break;
            case R.id.btn_del:
                DelQdDialogFragment.newInstance(info.getId()).showDialog(getChildFragmentManager());
                break;
            case R.id.btn_edit_dandeng:
                break;
            case R.id.btn_edit_shuangdeng:
                break;
            case R.id.btn_del_dandeng:
                DelDeviceDIalogFragment fragment = DelDeviceDIalogFragment.newInstance(info.getId());
                fragment.setOnDestroyListener(new BaseDialogFragment.OnDestroyListener() {
                    @Override
                    public void onDestroy(Object object, boolean isChange) {
                        if (isChange) {
                            EventBusUtils.post(new EditLampOkEvent());
                        }
                    }
                });
                fragment.showDialog(getChildFragmentManager());
                break;

            case R.id.btn_del_shuangdeng:
                DelDeviceDIalogFragment.newInstance(info.getId()).showDialog(getChildFragmentManager());
                break;
        }
    }

    private void showDialog(BaseDialogFragment fragment) {
        mHandler.obtainMessage(1).sendToTarget();
        fragment.showDialog(getChildFragmentManager());
        fragment.setOnDestroyListener(new BaseDialogFragment.OnDestroyListener() {
            @Override
            public void onDestroy(Object object, boolean isChange) {
                resetBtns();
                mHandler.obtainMessage(2).sendToTarget();
            }
        });
    }

    private void clickBottomBtn(int id) {
        resetBtns();
        mFlBtns.get(id).setEnabled(false);
        mFlBtns.get(id).setBackgroundResource(R.drawable.db_button_1_1);
        mTvBtns.get(id).setTextColor(mWhite);
        mTvBtns.get(id).setBackgroundResource(android.R.color.transparent);
    }

    private void resetBtns() {
        for (FrameLayout mFlBtn : mFlBtns) {
            mFlBtn.setEnabled(true);
            mFlBtn.setBackgroundResource(R.drawable.db_button_2_1);
        }
        for (TextView mTvBtn : mTvBtns) {
            mTvBtn.setTextColor(mBlue);
            mTvBtn.setBackgroundResource(R.drawable.s_bg_search);
        }
    }

}
